<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="Model.ProModel" %>
<%@page import="bean.*" %>
<%@page import="java.util.*"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Carts</title>
</head>
    <style>
        #tb td {border-color: #cccccc; text-align: center}
    </style>
    <script>
         function del(f)
         {
            
             if(f.ck.length==null )
             {
                 if(f.ck.checked==true)
                    f.IDs.value = f.ck.value;
                 return;
             }
             st = "";
             for(i = 0; i<f.ck.length;i++)
                 {
                    if(f.ck[i].checked==true)
                     {
                        st = st +","+ f.ck[i].value;
                     }
                 }
                 
             st = st.substring(st.indexOf(",")+1,st.length);
             f.IDs.value = st;
         }

         function reduce(e)
         {
             f = e.form;
             f.action="/BabyShop/client/pages/ReduceCart.dos";
             f.submit();
         }
         function buy(f)
         {
             cf = confirm("Ban co chac chan dat mua?")
             if(cf==true)
                 {
                     f.action= "/BabyShop/client/pages/buy.dos";
                     f.submit();
                 }
         }
      </script>
<body marginwidth="100px" bgcolor="#FFFFDD" >

<table width="100%" border="0" align="center" cellspacing="0px"  background= "../picture/background.jpg">
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>
	<jsp:include page="header.jsp" />	</td>
  </tr>
  <tr>
    <td>
        <table width="100%" border="0" cellspacing="0" id="tb">
      <tr>
        <td width="140" valign="top" style="border-right: 2px solid #cccccc" ><jsp:include page="left.jsp" /></td>
        <td valign="top">

            <html:form action="/client/pages/DeleteCart"  >

            <table width="100%" border="1" align="center" cellspacing="0" style="font-size: 20px; " >
          <tr>
              <td width="20%" align="center" >STT</td>
            <td width="14%" align="center">ID</td>
            <td width="26%" align="center"> Anh </td>
            <td width="20%" align="center">So luong </td>
            <td align="center" > Giam so luong </td>
            <td width="20%" align="center">Gia(VND) </td>
            <td> Xoa </td>
          </tr>
             <%
             ArrayList<CartBean> carts = new ArrayList<CartBean>();
             if(session.getAttribute("carts")!=null)
                carts.addAll((ArrayList<CartBean>)session.getAttribute("carts"));
             Iterator<CartBean> it = carts.iterator();
        CartBean cart;
        Product pro;
        int i=0;
        long tt=0;
        while(it.hasNext())
        {
            i++;
            cart=  it.next();
            pro = cart.getPro();
            tt = tt+(long)(cart.getAmount()*pro.getPrice()*(1-pro.getPromotion()/100));

			  %>
          <tr>
              <td><%=i%></td>
              <td><%=pro.getIDpro()%></td>
            <td><img src="../products/<%=pro.getImage()%>" style="width:100px; height:100px" /></td>
            <td><%=cart.getAmount()%></td>
            <td align ="center">
                <input type="image" name="IDpro" id="IDpro" value="<%=pro.getIDpro()%>" src="../picture/down.png" style="height:20px;width:10px" title="reduce" alt="reduce" onclick="reduce(this)" />
            </td>
                <td><%=pro.getPrice() %><% if(pro.getPromotion()>0) out.print("khuyen mai "+pro.getPromotion()+"%"); %></td>
            <td>
                
                <input type="checkbox" id="ck" name="ck" value="<%=pro.getIDpro() %>" />
            </td>
          </tr>
          <% } %>
          <tr>
              <td colspan="5">
                  <input type="button" onclick="buy(this.form)" value="Mua san pham" />
              </td>
              <td  align="right">Tong tien :<%=tt%>(VND) </td>
            
            <td>
                <input type="hidden" property="IDs" name="IDs" value="" />
                <html:submit value="Xoa" onclick="del(this.form)"  /></td>
          </tr>
        </table>

        </html:form>
        </td>
        <td width="140" valign="top" style="border-left: 2px solid #cccccc" ><jsp:include page="right.jsp" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>footer</td>
  </tr>
</table>
      
</body>
</html>
